<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">// The Antville Project</span><span class="WHIT">
<span class='line'>  2</span> </span><span class="COMM">// http://code.google.com/p/antville</span><span class="WHIT">
<span class='line'>  3</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='line'>  4</span> </span><span class="COMM">// Copyright 2007-2011 by Tobi Schäfer.</span><span class="WHIT">
<span class='line'>  5</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='line'>  6</span> </span><span class="COMM">// Copyright 2001–2007 Robert Gaggl, Hannes Wallnöfer, Tobi Schäfer,</span><span class="WHIT">
<span class='line'>  7</span> </span><span class="COMM">// Matthias & Michael Platzer, Christoph Lincke.</span><span class="WHIT">
<span class='line'>  8</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='line'>  9</span> </span><span class="COMM">// Licensed under the Apache License, Version 2.0 (the ``License'');</span><span class="WHIT">
<span class='line'> 10</span> </span><span class="COMM">// you may not use this file except in compliance with the License.</span><span class="WHIT">
<span class='line'> 11</span> </span><span class="COMM">// You may obtain a copy of the License at</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='line'> 13</span> </span><span class="COMM">//    http://www.apache.org/licenses/LICENSE-2.0</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="COMM">// Unless required by applicable law or agreed to in writing, software</span><span class="WHIT">
<span class='line'> 16</span> </span><span class="COMM">// distributed under the License is distributed on an ``AS IS'' BASIS,</span><span class="WHIT">
<span class='line'> 17</span> </span><span class="COMM">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span><span class="WHIT">
<span class='line'> 18</span> </span><span class="COMM">// See the License for the specific language governing permissions and</span><span class="WHIT">
<span class='line'> 19</span> </span><span class="COMM">// limitations under the License.</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="COMM">// $Revision$</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="COMM">// $Author$</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="COMM">// $Date$</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="COMM">// $URL$</span><span class="WHIT">
<span class='line'> 25</span> 
<span class='line'> 26</span> </span><span class="COMM">/**
<span class='line'> 27</span>  * @fileOverview Defines the Importer namespace.
<span class='line'> 28</span>  */</span><span class="WHIT">
<span class='line'> 29</span> 
<span class='line'> 30</span> </span><span class="COMM">/**
<span class='line'> 31</span>  * The Importer namespace provides methods for importing a site.
<span class='line'> 32</span>  * @namespace
<span class='line'> 33</span>  */</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">Importer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 35</span> 
<span class='line'> 36</span> </span><span class="COMM">/**
<span class='line'> 37</span>  * Imports a site and its content for the specified user.
<span class='line'> 38</span>  * @param {Site} site The site to import.
<span class='line'> 39</span>  * @param {User} user The user who will become the creator of the site’s imported content.
<span class='line'> 40</span>  */</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="NAME">Importer.run</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">site</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">user</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 42</span> </span><span class="WHIT">   </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 43</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">xml</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">File.getById</span><span class="PUNC">(</span><span class="NAME">site.import_id</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">xml</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">file</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">java.io.File</span><span class="PUNC">(</span><span class="NAME">xml.getFile</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">reader</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">rome.XmlReader</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">input</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">rome.SyndFeedInput</span><span class="PUNC">(</span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">feed</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">input.build</span><span class="PUNC">(</span><span class="NAME">reader</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">         </span><span class="NAME">Api.constrain</span><span class="PUNC">(</span><span class="NAME">site</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">user</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">         </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">&lt;</span><span class="NAME">feed.entries.size</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">+</span><span class="PUNC">=</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">entry</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">feed.entries.get</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">category</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">entry.categories.get</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">category.name</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"http://schemas.google.com/blogger/2008/kind#post"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">               </span><span class="KEYW">continue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">story</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Story.add</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">               </span><span class="NAME">title</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">entry.title</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">               </span><span class="NAME">text</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">entry.description</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">entry.contents.get</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">value</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">               </span><span class="NAME">created</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">entry.publishedDate.format</span><span class="PUNC">(</span><span class="STRN">"yyyy-MM-dd HH:mm"</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">               </span><span class="NAME">status</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Story.CLOSED</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">               </span><span class="NAME">mode</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Story.FEATURED</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">site</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">user</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">         </span><span class="NAME">File.remove.call</span><span class="PUNC">(</span><span class="NAME">xml</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">   </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">      </span><span class="NAME">app.log</span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">   </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 69</span> 
<span class='line'> 70</span> </span><span class="WHIT">   </span><span class="COMM">// Reset the site’s export status</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">   </span><span class="NAME">site.job</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">   </span><span class="NAME">site.import_id</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">   </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 75</span> </span></pre></body></html>